package com.waya.web.browser.util;

import android.util.Log;
import java.io.File;

/**
 * Created by JesseHev on 2018/1/11.
 * describe: webview 缓存工具
 *
 * 设置缓存，清除缓存，获取缓存路径
 */

public class WebCacheUtil {

  private static final String TAG = "WebCacheUtil";

  public void deleteFile(final File dir) {
    if (dir == null) {
      Log.i("Info", "dir:" + dir.getAbsolutePath());
      return;
    }
    if (dir.isFile()) {
      dir.delete();
      return;
    }
    if (dir.isDirectory()) {
      try {
        for (File child : dir.listFiles()) {
          if (child.isDirectory()) {
            deleteFile(child);
            return;
          }
          Log.i(TAG, "file name:" + child.getName());
          if (child.delete()) {
            Log.i(TAG, "文件：" + child.getAbsolutePath() + "删除成功");
          }
        }
      } catch (Exception e) {
        Log.e(TAG, String.format("Failed to delete the file, error===> %s", e.getMessage()));
      }
    }
  }
}
